﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace DesignPatterns
{
    public partial class FrmBase : Form
    {
        public FrmBase()
        {
            InitializeComponent();
        }

        public void RunUI(Action action)
        {
            BeginInvoke(action);
        }

        public bool RunThread(Action<object> action, object state)
        {
            return ThreadPool.QueueUserWorkItem(f => action(state), state);
        }

        public void WriteLog(string log)
        {
            Console.WriteLine($"[{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}]{log}");
        }

        public DialogResult ShowMessage(
            string message,
            string title = "提示",
            MessageBoxButtons buttons = MessageBoxButtons.OK,
            MessageBoxIcon icon = MessageBoxIcon.Information,
            MessageBoxDefaultButton defaultButton = MessageBoxDefaultButton.Button1)
        {
            return MessageBox.Show(message, title, buttons, icon, defaultButton);
        }
    }
}
